using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
	
	public float speed = 0.2f;
	private Vector3 move = Vector3.zero;
	
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		Move();
		
		if(Input.GetKey(KeyCode.Mouse0))
		{
			Shoot();
		}
		
		Debug.Log(rigidbody.velocity);
}
	 void Move()
	{
		
		if((Input.GetKey("w") && Input.GetKey("d")) || (Input.GetKey("s") && Input.GetKey("d")) || (Input.GetKey("w") && Input.GetKey("a")) || (Input.GetKey("s") && Input.GetKey("a")))
		{
			speed = 0.15f;
		}
		else 
		{
			speed = 0.2f;
		}
		if((Input.GetKey("w") && Input.GetKey("s")) || (Input.GetKey("a") && Input.GetKey("d")))
		{
			speed = 0;
		}
		
		move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        move = transform.TransformDirection(move);
		move *= speed;
		
		transform.position += move;
	}
	void Status()
	{
		
	}
	void Shoot()
	{
		Transform tiro = GameObject.FindGameObjectWithTag("Tiro").transform;
		RaycastHit hit;
		
		if(Physics.Raycast(tiro.position, transform.forward, out hit))
		{
			//Debug.DrawLine (tiro.transform.position, hit.transform);
			
			Transform temp = hit.transform;
			if(temp.tag == "Caixa")
			{
				
				Transform temp2 = hit.transform;
				Destroy(temp2.gameObject);
			}
		}
		
	}
}
